import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/views/TextView.dart';
import 'package:xin_nuo_pda/views/edittext/TitleEditText.dart';

import 'AddPartsController.dart';

class AddPartsPage extends StatelessWidget {
  final controller = Get.put(AddPartsController());
  final state = Get.find<AddPartsController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("添加部件"),
        actions: [
          Align(
            alignment: Alignment.centerRight,
            child: Container(
              height: 36,
              padding: EdgeInsets.fromLTRB(4, 0, 4, 0),
              margin: EdgeInsets.only(right: 8),
              child: OutlinedButton(
                style: OutlinedButton.styleFrom(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8.0),
                  ),
                  side: BorderSide(width: 1, color: Colors.white),
                ),
                onPressed: () {
                  if (controller.isInputData()) {
                    Get.back(result: {
                      "partsName": state.partsNameController.text,
                      "partsId": state.partsIdController.text
                    });
                  }
                },
                child: Text(
                  "添加",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          )
        ],
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              TextView("设备ID:", state.eqpId),
              TitleEditText(
                "部件名称:",
                "请输入部件名称",
                (value) {},
                controller: state.partsNameController,
              ),
              TitleEditText(
                "部件ID:",
                "请扫描或输入部件ID",
                (value) {},
                controller: state.partsIdController,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
